package xsis.music.dao.impl;

import java.util.Collection;

import org.hibernate.Criteria;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Order;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Service;

import xsis.music.dao.AdminDao;
import xsis.music.model.BarangModel;
import xsis.music.model.KategoriModel;
@Service
public class AdminDaoImpl extends HibernateDaoSupport implements AdminDao {

	@Autowired
	public AdminDaoImpl(SessionFactory sessionFactory) {
		setSessionFactory(sessionFactory);
	}
	@SuppressWarnings("unchecked")
	@Override
	public Collection<BarangModel> listAllBarang() throws Exception {
		// TODO Auto-generated method stub
		
		Criteria criteria = getSession().createCriteria(BarangModel.class);
		criteria.addOrder(Order.desc("id_barang"));
		
		return criteria.list();
	}
	@Override
	public Collection<KategoriModel> listAllKategori() throws Exception {
		// TODO Auto-generated method stub
		Criteria criteria = getSession().createCriteria(KategoriModel.class);
		criteria.addOrder(Order.desc("id_kategori"));
		
		return criteria.list();
	}

}
